var http=require('http');
var fs=require('fs');
var url=require('url');
var path=require('path');

//创建服务器
http.createServer(function(req,res)
{
    console.log("req is "+req.url);
    var pathname=url.parse(req.url).pathname;
    console.log("Request for "+pathname+" received.");
    console.log('path:'+pathname.substr(1));
    // pathname=path.join(process.cwd(), pathname.substr(1));
    //
    fs.readFile( path.dirname(__filename) + pathname,function(err,data)
    {
        if(err) {
            console.error(err);

            res.writeHead(404, {'Content-Type': 'text/html'});
        }
        else
        {
            res.writeHead(200,{'Content-Type':'text/html'});
            res.write(data.toString());
        }

        res.end();
    });

}).listen(8888);


console.log('Server running at http:127.0.01:8888/');